package com.mp.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.dcy.model.BootStrapTable;
import com.mp.entity.Role;
import com.mp.mapper.RoleMapper;
import com.mp.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.dcy.utils.lang.StringUtils;

import java.util.List;
/**
  * <p>
  *  服务实现类
  * </p>
  *
  * @author ShouSi
  * @since 2020-06-23
  */
@Service
@Transactional
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public Page<Role> selectPage(BootStrapTable<Role> bootStrapTable, Role role) {
    EntityWrapper<Role> entityWrapper = new EntityWrapper<Role>();
    getEntityWrapper(entityWrapper,role);
    return super.selectPage(bootStrapTable.getPagePlus(),entityWrapper);
    }

    @Override
    public List<Role> selectList(Role role) {
        EntityWrapper<Role> entityWrapper = new EntityWrapper<Role>();
        getEntityWrapper(entityWrapper,role);
        return super.selectList(entityWrapper);
    }

    /**
    *  公共查询条件
    * @param entityWrapper
    * @return
    */
    public EntityWrapper<Role> getEntityWrapper(EntityWrapper<Role> entityWrapper,Role role){
        //条件拼接
                    if (StringUtils.isNotBlank(role.getRname())){
    entityWrapper.like(Role.RNAME,role.getRname());
    }
                if (StringUtils.isNotBlank(role.getUid())){
    entityWrapper.like(Role.UID,role.getUid());
    }
                return entityWrapper;
    }
}